// pages/myorderbox/sendsuccess/sendsuccess.js
import {
  getOrderDetail
} from '../../../utils/networkRequest.js'
import {
  errorMsg
} from '../../../utils/tool.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dataInfo: null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    getOrderDetail(options.oid, (r) => {
      if (r.code == 0) {
        debugger;
        let dataInfo = r.data;
        if (dataInfo.express_info && dataInfo.express_info.data) {
          dataInfo.express_info.data.map((o, i) => {
            o.m = o.time.substr(5, 5);
            o.t = o.time.substr(11, 5);
          })
        }
        if (!dataInfo.mine){
          wx.hideShareMenu();
        } 
        this.setData({
          dataInfo: dataInfo
        })
        
      } else {
        errorMsg(r.message);
      }

    })

  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function(res) {
    debugger;
   
      if (res.from === 'button') {
        // 来自页面内转发按钮
        console.log(res.target)
      }
      return {
        title: '请核对您的订单，点击实时查询物流信息',
        imageUrl: this.data.dataInfo.order.items[0].imgSrc,
        path: "pages/myorderbox/vieworderdetail/vieworderdetail?orderId=" + this.data.dataInfo.order_id
      }
     
    
  },
  //图片预览
  previewImage: function(e) {
    var current = e.currentTarget.dataset.src;
    wx.previewImage({
      current: current[0], // 当前显示图片的http链接		  	
      urls: current // 需要预览的图片http链接列表	
    })
  },
   
  //复制
  onCopy: function (e) {
    let {
      name,
      mobile,
      address
    } = e.currentTarget.dataset;
    wx.setClipboardData({
      data: "收件人:" + name + "\r\n" + "电话:" + mobile + "\r\n" + "地址:" + address + "\r\n",
      success() {
        errorMsg("复制成功")
      }
    })
  },
  //查看物流
  goExpView:function(e){
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../viewexpress/viewexpress?id=' + id,
    })
  }

})